home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Source / Control Stuff / SkelDrawButtonOutline.c next >
Text File  |  1996-01-17  |  2KB  |  83 lines

  1. /*
  2.  * Draw a heavy outline around a push button.  Draw the outline in black
  3.  * unless the button is inactive, in which case draw it gray.  When drawing
  4.  * gray outlines, use a true RGB gray if the monitor supports it and the button
  5.  * belongs to a color GrafPort, and pattern gray otherwise.  This matches how
  6.  * the Control Manager draws titles in dimmed buttons.
  7.  *
  8.  * It's absolutely astonishing how much work is necessary to draw a gray
  9.  * outline. This is evidenced not only by all the code below, but also by
  10.  * the efforted expended in SkelGetRectDevice() to make sure the gray is
  11.  * computed using the characteristics of the proper device.  It's a wonder
  12.  * it doesn't take 10 minutes to draw dimmed outlines.
  13.  */
  14.  
  15. # include    <Palettes.h>        /* for GetGray() */
  16.  
  17. # include    "TransSkel.h"
  18.  
  19.  
  20. # define    normalHilite    0
  21. # define    dimHilite        255
  22.  
  23.  
  24. pascal void
  25. SkelDrawButtonOutline (ControlHandle ctrl)
  26. {
  27. GrafPtr        oldPort;
  28. PenState    penState;
  29. Rect        r, r2;
  30. short        curvature;
  31. Boolean        haveRGBGray;
  32. RGBColor    fgColor, newFgColor, bgColor;
  33. GDHandle    gDev;
  34.  
  35.     GetPort (&oldPort);
  36.     SetPort ((**ctrl).contrlOwner);
  37.     GetPenState (&penState);
  38.     PenNormal ();
  39.     r = (**ctrl).contrlRect;
  40.     InsetRect (&r, -4, -4);
  41.     curvature = (r.bottom - r.top) / 2 + 2;
  42.     PenSize (3, 3);
  43.     if ((**ctrl).contrlHilite == normalHilite)    /* button active, draw black */
  44.         FrameRoundRect (&r, curvature, curvature);
  45.     else                                        /* button inactive, draw gray */
  46.     {
  47.         /*
  48.          * Try to get RGB gray value appropriate for the device on which
  49.          * the button is displayed if have color GrafPort.
  50.          */
  51.         haveRGBGray = false;
  52.         if (((CGrafPtr) (**ctrl).contrlOwner)->portVersion & 0xc000)
  53.         {
  54.             /* convert rect to global coordinates */
  55.             r2 = r;
  56.             LocalToGlobal (&topLeft (r2));
  57.             LocalToGlobal (&botRight (r2));
  58.             (void) SkelGetRectDevice (&r2, &gDev, (Rect *) nil, (Boolean *) nil);
  59.             /* test unnecessary unless for some reason rect isn't on any device! */
  60.             if (gDev != (GDHandle) nil)
  61.             {
  62.                 GetBackColor (&bgColor);
  63.                 GetForeColor (&fgColor);
  64.                 newFgColor = fgColor;
  65.                 haveRGBGray = GetGray (gDev, &bgColor, &newFgColor);
  66.             }
  67.         }
  68.         /*
  69.          * Draw using colored gray if possible, else using pattern gray
  70.          */
  71.  
  72.         if (haveRGBGray)
  73.             RGBForeColor (&newFgColor);
  74.         else
  75.             PenPat ((ConstPatternParam) &SkelQD (gray));
  76.         FrameRoundRect (&r, curvature, curvature);
  77.         if (haveRGBGray)
  78.             RGBForeColor (&fgColor);
  79.     }
  80.     SetPenState (&penState);
  81.     SetPort (oldPort);
  82. }
  83.